package com.woniuxy.commons.enums;

import com.woniuxy.commons.entity.Dict;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * TODO:对应数据字典的id,name,dictcode
 **/
@Getter
@SuppressWarnings("all")
public enum DictCodeEnum {

    ROOT(1, "全部分类", "ROOT"),

    REGION(2, "区域", "REGION"),

    HUA_NAN_REGION(3, "华南区域", "HUA_NAN_REGION"),

    DONG_BEI_REGION(4, "东北区域", "DONG_BEI_REGION"),

    XI_NAN_REGION(5, "西南区域", "XI_NAN_REGION"),

    PRODUCT_LINE(15, "产品线", "PRODUCT_LINE"),

    CATEGORY(21, "品类", "CATEGORY"),

    WORKMANSHIP(24, "工艺", "WORKMANSHIP"),

    CONDITION(27, "成色", "CONDITION"),

    ITEM_TYPE(30, "物品类型", "ITEM_TYPE"),

    FORM_TYPE(33, "表单类型", "FORM_TYPE"),

    EX_WAREHOUSE(34, "出库", "EX_WAREHOUSE"),

    WAREHOUGING(37, "入库", "WAREHOUGING"),

    STATUS(40, "状态", "STATUS"),

    STOCK_IN_AND_OUT(41, "出入库字典", "STOCK_IN_AND_OUT"),

    PRODUCE_STATUS(46, "产品状态", "PRODUCE_STATUS"),

    DEMAND_ORDER_STATUS(49, "需求单状态", "DEMAND_ORDER_STATUS"),

    DEMAND_ORDER_LIST_ST(54, "需求单列表状态", "DEMAND_ORDER_LIST_ST"),

    ALL_REQU_STATUS(59, "分配需求单状态", "ALL_REQU_STATUS"),

    ALL_REQU_LIST_STATUS(63, "分配需求列表状态", "ALL_REQU_LIST_STATUS"),

    PUR_ORDER_STATUS(68, "采购单状态", "PUR_ORDER_STATUS"),

    CHOOSE_ORDER_STATUS(72, "选货单列表状态", "CHOOSE_ORDER_STATUS"),

    PACK_LIST_STATUS(76, "打包单列表状态", "PACK_LIST_STATUS"),

    SETT_DOC_LIST_STATUS(81, "结算单列表状态", "SETT_DOC_LIST_STATUS"),

    PER_GRAM(84, "克供费", "PER_GRAM"),

    ;

    /**
     * TODO 枚举的id 对应数据库的id
     */
    private int id;

    /**
     * TODO 对应数据字典的name字段
     */
    private String name;

    /**
     * TODO 对应数据字典的dict_code
     */
    private String dictCode;

    private DictCodeEnum(Integer id, String name, String dictCode) {
        this.id = id;
        this.name = name;
        this.dictCode = dictCode;
    }

    /**
     * <P>Author ideaAdmin
     * <P>TODO:输入对应的id 获得对应的dict_code
     * <P>Date 13:36 2022/4/19
     * <P>* @param id
     * <P>* @return java.lang.String
     **/
    public static  String getDictCodeStr(int id) {

        try {
            // DictCodeEnum.values()会返回
            Optional<String> dict = Arrays.stream(DictCodeEnum.values())
                    .filter(dictCodeEnum -> {
                        return dictCodeEnum.getId() == id;
                    })
                    .map(dictCodeEnum -> dictCodeEnum.getDictCode())
                    .findFirst();
            return dict.get();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }


    /**
     * <P>Author ideaAdmin
     * <P>TODO:输入对应的dict_code 获得对应在表中的id
     * <P>Date 13:36 2022/4/19
     * <P>* @param id
     * <P>* @return java.lang.String
     **/
    public static Integer getDictCodeId(String dictCode) {
        try {
            Optional<Integer> dict = Arrays.stream(DictCodeEnum.values())
                    .filter(dictCodeEnum -> {
                        return dictCodeEnum.getDictCode().equals(dictCode);
                    })
                    .map(dictCodeEnum -> dictCodeEnum.getId())
                    .findFirst();
            return dict.get();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }


    /**
     * <P>Author ideaAdmin
     * <P>TODO:输入对应的id 获得对应的枚举
     * <P>Date 13:36 2022/4/19
     * <P>* @param id
     * <P>* @return java.lang.String
     **/
    public static  DictCodeEnum getDictCode(int id) {

        try {
            // DictCodeEnum.values()会返回
            Optional<DictCodeEnum> dict = Arrays.stream(DictCodeEnum.values())
                    .filter(dictCodeEnum -> {
                        return dictCodeEnum.getId() == id;
                    })
                    .findFirst();
            return dict.get();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

}
